package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.SysRoleDao;
import com.bestv.search.common.dataSource.DataSourceKey;
import com.bestv.search.common.model.SysRole;
import com.bestv.search.common.model.uid.UID;
import com.bestv.search.common.service.SysRoleManager;

import java.util.List;

public class SysRoleManagerImpl implements SysRoleManager {

    private SysRoleDao sysRoleDao;

    public SysRoleManagerImpl() {
    }

    public SysRoleDao getSysRoleDao() {
        return sysRoleDao;
    }

    public void setSysRoleDao(SysRoleDao sysRoleDao) {
        this.sysRoleDao = sysRoleDao;
    }

    @Override
    public SysRole getRoleByID(DataSourceKey key, Long id) {
        return sysRoleDao.get(id);
    }

    @Override
    public List<SysRole> getRoles(DataSourceKey key) {
        return sysRoleDao.getAll();
    }

    @Override
    public SysRole getRolesByName(DataSourceKey key, String name) {
        return sysRoleDao.getRolesByName(name);
    }

    @Override
    public SysRole saveRole(DataSourceKey key, SysRole role) {
        if (role.getId() == 0L) {
            role.setId(new Long(UID.getUID(role)));
        }
        return sysRoleDao.saveOrUpdate(role);
    }
}
